grpcreplay: reject oversized record size in readRecord to prevent OOM#67
Merged
Merged
Conversation
readRecord() reads size as a raw uint32 from the replay file and passes it directly to make([]byte, size) with no bounds check. A crafted 13-byte .grpc_replay file with size=0xFFFFFFFF triggers a 4 GB allocation in any program calling NewReplayer() on an attacker-supplied file. Add maxRecordSize (64 MiB; gRPC default max message size is 4 MiB) and reject records that exceed it before allocation. Add TestOversizeRecord to prevent regression.
jba
approved these changes
May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
readRecord()ingrpcreplay/binary_format.goreadssizeas a rawuint32from the replay file and passes it directly to
make([]byte, size)with nobounds check. A crafted 13-byte
.grpc_replayfile can trigger a 4 GBallocation in any program that calls
grpcreplay.NewReplayer()on anattacker-supplied file.
Vulnerable code (before this fix)
Trigger file (13 bytes)
RPCReplay(9 bytes)0xffffffff(4 bytes LE)Standalone reproducer output (size capped at 512 MB to avoid crashing the host):
Fix
Add
maxRecordSize = 64 MiBconstant (gRPC's own default max message sizeis 4 MiB; 64 MiB is a generous upper bound) and reject records that exceed
it before allocation.
Testing
TestOversizeRecordingrpcreplay_test.goverifies thatreadRecord()returns an error for an oversized size field without causing a large allocation.